home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 23 / AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso / Tools / Text-Viewer / MSWordView / mswordview_src / blip.test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-06  |  12.5 KB  |  497 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include "config.h"
  6. #include "mswordview.h"
  7.  
  8. extern FILE *outputfile;
  9. extern FILE *erroroutput;
  10. extern char *outputfilename;
  11. extern char *imagesdir;
  12.  
  13. extern int madeinmac;
  14.  
  15. extern char failsafe[1];
  16.  
  17. extern int errno;
  18.  
  19. U16 idlist[NOOFIDS] = {0,0x216,0x3D4,0x542,0x6E0,0x46A,0x7A8,0x800};
  20.  
  21.  
  22. long get_picture_header(U32 fcPic,FILE *data, U32 *len, U16 *datatype)
  23.     {
  24.     U8 i,j;
  25.     error(erroroutput,"seeking to %x\n",fcPic);
  26.     fseek(data,fcPic,SEEK_SET);
  27.     *len = read_32ubit(data);
  28.     error(erroroutput,"the no of bytes in this PIC is %d\n",*len);
  29.     i = getc(data);
  30.     error(erroroutput,"the no of bytes of the PIC is %x\n",i);
  31.     *datatype = read_16ubit(data);
  32.     error(erroroutput,"an mm is %x\n",*datatype);
  33.     error(erroroutput,"an mm is %x\n",read_16ubit(data));
  34.     error(erroroutput,"an mm is %x\n",read_16ubit(data));
  35.     error(erroroutput,"an mm is %x\n",read_16ubit(data));
  36.     for (j=0;j<(i-13);j++)
  37.         getc(data);
  38.     *len = *len - i;
  39.     return(ftell(data));
  40.     }
  41.  
  42.  
  43. obj_by_spid * get_blips(U32 fcDggInfo,U32 lcbDggInfo,FILE *tablefd,FILE *mainfd,int *noofblips,int streamtype,obj_by_spid **realhead)
  44.     {
  45.     U16 element;
  46.     U32 len;
  47.     U32 fulllen=0;
  48.     U32 noofpics;
  49.     U32 offset;
  50.     int i;
  51.     FILE *graphic;
  52.     char *buffer=NULL;
  53.     obj_by_spid *head=NULL;
  54.     obj_by_spid *p=NULL;
  55.     char *imageprefix=NULL;
  56.  
  57.     int currentspid=0;
  58.     
  59.     U16 spids[1024];
  60.     char **names;
  61.     int *no;
  62.     char *names01[1024];
  63.     static char *names08[1024];
  64.     static int no01=0;
  65.     static int no08=0;
  66.  
  67.     U16 id;
  68.     U32 op;
  69.     U16 msofbh;
  70.     U16 extra=0;
  71.     U32 flags;
  72.  
  73.     *noofblips=0;
  74.  
  75.     if (imagesdir == NULL)
  76.         {
  77.         imageprefix = malloc(strlen(outputfilename)+1);
  78.         if (imageprefix == NULL)
  79.             {
  80.             fprintf(erroroutput,"arrgh, no mem\n");
  81.             exit(-1);
  82.             }
  83.         strcpy(imageprefix,outputfilename);
  84.         }
  85.     else
  86.         {
  87.         imageprefix = malloc(strlen(imagesdir)+2+strlen(ms_basename(outputfilename)));
  88.         if (imageprefix == NULL)
  89.             {
  90.             fprintf(erroroutput,"arrgh, no mem\n");
  91.             exit(-1);
  92.             }
  93.         sprintf(imageprefix,"%s/%s",imagesdir,ms_basename(outputfilename));
  94.         }
  95.  
  96.  
  97.     if (streamtype == 0x01)
  98.         {
  99.         mainfd=tablefd;
  100.         names=names01;
  101.         no = &no01;
  102.         memset(names, 0, 1024);
  103.         }
  104.     else        
  105.         {
  106.         names=names08;
  107.         no = &no08;
  108.         }
  109.  
  110.     if ( (*no) == 0)    
  111.         memset(names, 0, 1024);
  112.  
  113.     if ((realhead != NULL) && (*realhead != NULL))
  114.         {
  115.         error(erroroutput,"adding onto an existing list\n");
  116.         p=*realhead;
  117.         head=*realhead;
  118.         error(erroroutput,"REAL TEST, filename is %s\n",(*realhead)->filename);
  119.         error(erroroutput,"head isnt null here\n");
  120.  
  121.         error(erroroutput,"TEST, no is %d, filename is %s\n",*no,p->filename);
  122.  
  123.         while (p->next != NULL)
  124.             p = p->next;
  125.         }
  126.  
  127.     fseek(tablefd,fcDggInfo,SEEK_SET);
  128.  
  129.     while(fulllen < lcbDggInfo)
  130.         {
  131.         error(erroroutput,"at this moment fullen is %d, lcbDggInfo is %d\n",fulllen,lcbDggInfo);
  132.         msofbh = read_16ubit(tablefd);
  133.         element = read_16ubit(tablefd);
  134.         len = read_32ubit(tablefd);
  135.  
  136.         fulllen+=8;
  137.         error(erroroutput,"len is %x, element is %x\n",len,element);
  138.         error(erroroutput,"dec, fullen is %d, lcbDggInfo is %d\n",fulllen,lcbDggInfo);
  139.         switch (element)
  140.             {
  141.             case 0xF000:
  142.                 /*keep going*/
  143.                 break;
  144.             case 0xf006:
  145.                 error(erroroutput,"1-->%d\n",read_32ubit(tablefd));
  146.                 error(erroroutput,"2-->%d\n",read_32ubit(tablefd));
  147.                 error(erroroutput,"3-->%d\n",read_32ubit(tablefd));
  148.                 noofpics = read_32ubit(tablefd);
  149.                 fulllen+=16;
  150.                 error(erroroutput,"there are %d pics visible\n",noofpics);
  151.                 /*
  152.                 for (i=0;i<noofpics;i++)
  153.                     {
  154.                     read_32ubit(tablefd);
  155.                     read_32ubit(tablefd);
  156.                     fulllen+=8;
  157.                     }
  158.                 */
  159.                 for (i=16;i<len;i++)
  160.                     {
  161.                     getc(tablefd);
  162.                     fulllen++;
  163.                     }
  164.                 break;
  165.             case 0xf001: /*container for pics*/
  166.                 break;
  167.             case 0xf002: /*container for page or something*/
  168.                 break;
  169.             case 0xf003: /*container for many shapes*/
  170.                 break;
  171.             case 0xf004: /*container for a shape*/
  172.                 break;
  173.             case 0xf005: /*container for shape rules*/
  174.                 break;
  175.             case 0xf007: /*a pic, yeah!!*/
  176.                 error(erroroutput,"window pic type is %d\n",getc(tablefd));    
  177.                 error(erroroutput,"mac pic type is %d\n",getc(tablefd));    
  178.                 fulllen+=2;
  179.                 for(i=0;i<18;i++)
  180.                     getc(tablefd);
  181.                 fulllen+=18;
  182.                 error(erroroutput,"pic data len is (%x)\n",read_32ubit(tablefd));
  183.                 error(erroroutput,"blid no is %d\n",read_32ubit(tablefd));
  184.                 offset = read_32ubit(tablefd);
  185.                 fulllen+=12;
  186.                 error(erroroutput,"file offset into main stream is %x\n",offset);
  187.  
  188.                 read_32ubit(tablefd);
  189.                 fulllen+=4;
  190.  
  191.                 buffer = malloc(strlen("-graphic100-mswv.tiff")+80+strlen(imageprefix));
  192.                 if (buffer==NULL)
  193.                     {
  194.                     fprintf(erroroutput,"no mem\n");
  195.                     exit(-1);
  196.                     }
  197.  
  198.                 error(erroroutput,"were at %x\n",ftell(tablefd));
  199.                 if ((offset != 0xffffffffUL) || (streamtype == 0x01))
  200.                     {
  201.                     if (streamtype == 0x08)
  202.                         fseek(mainfd,offset,SEEK_SET);
  203.                     error(erroroutput,"were at %x\n",ftell(mainfd));
  204.                     msofbh = read_16ubit(mainfd);
  205.                     error(erroroutput,"element is %x, inst is %x\n",msofbh ,msofbh>> 4);
  206.                     msofbh = msofbh >> 4;
  207.                     for (i=0;i<NOOFIDS;i++)
  208.                         {
  209.                         if ((msofbh ^ idlist[i]) == 1)
  210.                             {
  211.                             error(erroroutput,"extra 16\n");
  212.                             extra=16;
  213.                             }
  214.                         }
  215.                     element = read_16ubit(mainfd);
  216.                     len = read_32ubit(mainfd);
  217.                     if (streamtype == 0x01)
  218.                         fulllen+=8;
  219.                     error(erroroutput,"graphic len is %x\n",len);
  220.                     if ((element >= 0xf018) && (element <= 0xf117))
  221.                         {
  222.                         switch (element - 0xf018)
  223.                             {
  224.                             case 6:
  225.                                 sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"png");
  226.                                 for(i=0;i<(17+extra);i++)
  227.                                     getc(mainfd);
  228.                                 len-=(17+extra);
  229.                                 if (streamtype == 0x01)
  230.                                     fulllen+=(17+extra);
  231.                                 break;
  232.                             case 5:
  233.                                 sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"jpg");
  234.                                 for(i=0;i<(17+extra);i++)
  235.                                     getc(mainfd);
  236.                                 len-=(17+extra);
  237.                                 if (streamtype == 0x01)
  238.                                     fulllen+=(17+extra);
  239.                                 break;
  240.                             case 4:
  241.                                 sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"pict");
  242.                                 for(i=0;i<(17+extra);i++)
  243.                                     getc(mainfd);
  244.                                 len-=(17+extra);
  245.                                 if (streamtype == 0x01)
  246.                                     fulllen+=(17+extra);
  247.                                 break;
  248.                             case 3:
  249.                                 sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"wmf.?gz");
  250.                                 for(i=0;i<16;i++)
  251.                                     getc(mainfd);
  252.                                 error(erroroutput,"uncompressed size would be %d\n",read_32ubit(mainfd));
  253.                                 for(i=0;i<24;i++)
  254.                                     getc(mainfd);
  255.                                 error(erroroutput,"compressed size is %d\n",read_32ubit(mainfd));
  256.                                 error(erroroutput,"compression is %d\n",getc(mainfd));
  257.                                 error(erroroutput,"filter is %d\n",getc(mainfd));
  258.                                 len-=50;
  259.                                 if (streamtype == 0x01)
  260.                                     fulllen+=50;
  261.                                 break;
  262.                             case 2:
  263.                                 sprintf(buffer,"%s-graphic%d-mswv-%d.%s",imageprefix,(*no)+1,streamtype,"emf.?gz");
  264.                                 for(i=0;i<16;i++)
  265.                                     getc(mainfd);
  266.                                 error(erroroutput,"uncompressed size would be %d\n",read_32ubit(mainfd));
  267.                                 for(i=0;i<24;i++)
  268.                                     getc(mainfd);
  269.                                 error(erroroutput,"compressed size is %d\n",read_32ubit(mainfd));
  270.                                 error(erroroutput,"compression is %d\n",getc(mainfd));
  271.                                 error(erroroutput,"filter is %d\n",getc(mainfd));
  272.                                 len-=50;
  273.                                 if (streamtype == 0x01)
  274.                                     fulllen+=50;
  275.                                 break;
  276.                             default:
  277.                                 sprintf(buffer,"%s-graphic-dontknow%d-mswv-%d.jpg",imageprefix,(*no)+1,streamtype);
  278.                                 break;
  279.                             }
  280.  
  281.                         names[(*no)++] = buffer;
  282.  
  283.                         error(erroroutput,"name is %s, index %d\n",names[(*no)-1],(*no)-1);
  284.  
  285.                         error(erroroutput,"the current pos of the beast is %x\n",ftell(mainfd));
  286.                         graphic = fopen(buffer,"wb");
  287.                         if (graphic == NULL)
  288.                             {
  289.                             fprintf(erroroutput,"warning couldnt create file %s, ignoring \n(failure was :%s)\n",buffer,strerror(errno));
  290.                             for (i=0;i<len;i++)
  291.                                 {
  292.                                 getc(mainfd);
  293.                                 if (streamtype == 0x01)
  294.                                     fulllen++;
  295.                                 }
  296.                             }
  297.                         else
  298.                             {
  299.                             error(erroroutput,"len changed to %x\n",len);
  300.                             for (i=0;i<len;i++)
  301.                                 {
  302.                                 putc(getc(mainfd),graphic);
  303.                                 if (streamtype == 0x01)
  304.                                     fulllen++;
  305.                                 }
  306.                             fclose(graphic);
  307.                             }
  308.                         }
  309.                     error(erroroutput,"blit no %d is filename %s\n",no,names[(*no)-1]);
  310.  
  311.  
  312.                     if (p != NULL)
  313.                         if (p->filename == NULL)
  314.                             p->filename = buffer;
  315.                     
  316.                     error(erroroutput,"THE FILENAME is %s\n",buffer);
  317.                     }
  318.                 else
  319.                     {
  320.                     error(erroroutput,"would have been %s-graphic-badoffset%d-mswv.jpg",imageprefix,(*no)+1);
  321.                     error(erroroutput,"THE FILENAME is %s\n",buffer);
  322.                     free(buffer);
  323.                     }
  324.                 break;
  325.             case 0xf11e:
  326.                 /*i dont quite understand this for now*/
  327.                 len=25;
  328.                 for(i=0;i<len;i++)
  329.                     {
  330.                     getc(tablefd);
  331.                     fulllen++;
  332.                     }
  333.                 break;
  334.             case 0xf008:
  335.                 read_32ubit(tablefd);    
  336.                 read_32ubit(tablefd);    
  337.                 fulllen+=8;
  338.                 break;
  339.             case 0xf00a:
  340.                 spids[currentspid++] = read_32ubit(tablefd);
  341.                 error(erroroutput,"The ID of this ENTITY is %x\n",spids[currentspid-1]);
  342.                 /*
  343.                 this is the identity of the object, the real spid as far 
  344.                 as im concerned, following this will be the shape property
  345.                 table that will have a list of blits associated with
  346.                 this id, (referred to by an index into the previous blit 
  347.                 table)
  348.                 */
  349.                 flags = read_32ubit(tablefd);
  350.                 error(stderr,"flags is %x\n",flags);
  351.  
  352.                 if (head == NULL)
  353.                     {
  354.                     head = (obj_by_spid*) malloc(sizeof(obj_by_spid));
  355.                     error(erroroutput,"head is null\n");
  356.                     if (head == NULL)
  357.                         {
  358.                         error(erroroutput,"no mem\n");
  359.                         exit(-1);
  360.                         }
  361.                     p = head;
  362.                     }
  363.                 else
  364.                     {
  365.                     p->next = (obj_by_spid*) malloc(sizeof(obj_by_spid));
  366.                     error(erroroutput,"head is not null\n");
  367.                     if (p->next == NULL)
  368.                         {
  369.                         error(erroroutput,"no mem\n");
  370.                         exit(-1);
  371.                         }
  372.                     p = p->next;
  373.                     }
  374.                 
  375.                 p->spid = spids[currentspid-1];
  376.                 p->filename = failsafe;
  377.                 error(erroroutput,"TEST-->%x %d \n",p->spid,op);
  378.                 p->next = NULL;
  379.                 (*noofblips)++;
  380.                 
  381.                 fulllen+=8;
  382.                 for(i=0;i<len-8;i++)
  383.                     {
  384.                     getc(tablefd);
  385.                     fulllen++;
  386.                     }
  387.                 break;
  388.             case 0xf00b:
  389.                 id = read_16ubit(tablefd);
  390.                 op = read_32ubit(tablefd);
  391.                 error(erroroutput,"id is %x\n",id);
  392.                 error(erroroutput,"op is %x\n",op);
  393.  
  394.                 if ((id & 0x4000) && (!(id & 0x8000)))
  395.                     {
  396.                     error(erroroutput,"talking about blit id of %x,mine %x\n",op,id&0x3fff);
  397.                     p->filename=names[op-1];
  398.                     if (p->filename==NULL)
  399.                         {
  400.                         /*
  401.                         this means that there was no blip in the blip store to match with this,
  402.                         from looking at it it looks like this means that there will be data in
  403.                         the client data to fill this blank
  404.                         so im going to temporarily allow a temp in the filename when we come
  405.                         to blips to be assigned
  406.                         */
  407.                         }
  408.                     }
  409.  
  410.                 if (p==NULL)
  411.                     error(erroroutput,"SO p is NULL\n");
  412.                 else if (p->filename == NULL)
  413.                     error(erroroutput,"SO p->filenamae is NULL\n");
  414.                 else
  415.                     error(erroroutput,"SO spid %x has a filename of %s\n",p->spid,p->filename);
  416.  
  417.                 fulllen+=6;
  418.                 for(i=0;i<len-6;i++)
  419.                     {
  420.                     getc(tablefd);
  421.                     fulllen++;
  422.                     }
  423.                 break;
  424.             default:
  425.                 error(erroroutput,"unrecognized element %x len is %d\n",element,len);
  426.                 error(erroroutput,"were here at %x\n",ftell(tablefd));
  427.                 for(i=0;i<len;i++)
  428.                     {
  429.                     getc(tablefd);
  430.                     fulllen++;
  431.                     }
  432.                 break;
  433.             }
  434.         }
  435.  
  436.     p=head;
  437.     error(erroroutput,"-->no is %d\n",(*no));
  438.     for (i=0;i<(*no);i++)
  439.         {
  440.         error(erroroutput,"-->filename is %s\n",names[i]);
  441.         error(erroroutput,"-->spid is %x\n",spids[i]);
  442.         }
  443.     p=head;
  444.     while (p != NULL)
  445.         {
  446.         error(erroroutput,"-->p->filename is %s\n",p->filename);
  447.         error(erroroutput,"-->p->spid is %x\n",p->spid);
  448.         p = p->next;
  449.         }
  450.     if (imageprefix != NULL)
  451.         free(imageprefix);
  452.     return(head);
  453.     }
  454.  
  455. void output_draw(U32 cp,textportions *portions)
  456.     {
  457.     int i;
  458.     U16 ourspid=0;
  459.     obj_by_spid *p;
  460.     char *temppointer;
  461.  
  462.  
  463.     for (i=0;i<portions->noofficedraw;i++)
  464.         {
  465.         if (cp == portions->officedrawcps[i])
  466.             {
  467.             ourspid = portions->spids[i];
  468.             break;
  469.             }
  470.         }
  471.     
  472.     error(erroroutput,"outspid is %x in output_draw, only able to handle blips, not real draw objects as of yet\n",ourspid);
  473.  
  474.     error(erroroutput,"noofficedraw is %d portions->noofblipdata is %d\n",portions->noofficedraw,portions->noofblipdata);
  475.  
  476.     p = portions->ablipdata;
  477.  
  478.     if ((ourspid != 0) && (p != 0)) /*Craig J Copi <cjc5@po.cwru.edu>*/
  479.         {
  480.         /*search to see if theres a filename assiciated with this spid*/
  481.         for(i=0;i<portions->noofblipdata;i++)
  482.             {
  483.             error(erroroutput,"p->spid is %x\n",p->spid);
  484.             error(erroroutput,"p->filename is %s\n",p->filename);
  485.             if (ourspid == p->spid)
  486.                 {
  487.                 outputimgsrc(p->filename);
  488.                 return;
  489.                 }
  490.             p = p->next;
  491.             }
  492.         }
  493.     error(erroroutput,"given spid %x, no luck\n",ourspid);
  494.     }
  495.  
  496.  
  497.